﻿package mortal.game.view.petNew.view
{
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.mount.panel.*;
    import mortal.game.view.wizard.panel.*;
    import mortal.mvc.core.*;

    public class PetInfoEpuipPanel extends GSprite
    {
        protected var _leftBg:GBitmap;
        protected var _rBg:GBitmap;
        protected var _leftOpenTxt:GTextFiled;
        protected var _rightOpenTxt:GTextFiled;
        protected var _grouthBg1:GBitmap;
        protected var _grouthBg2:GBitmap;
        protected var _petGrouthItem:BaseItem;
        protected var _petTalentItem:BaseItem;
        private var _mountSharpItem:OtherEquipItem;
        private var _isHideFasion:GCheckBox;
        protected var _wardrobeEnterBtn:GLoadingButton;
        private var _itemArr:Array;
        private var _petGrouthUseBtn:GLoadedButton;
        private var _petTalentUseBtn:GLoadedButton;
        private var _petData:SPublicPet2;
        private var _growSp:GSprite;
        private var _talentSp:GSprite;
        private var _posArr:Array;
        public static const grouthItemCode:int = 410520001;
        public static const tatlentItemCode:int = 410510001;

        public function PetInfoEpuipPanel()
        {
            this._posArr = [new Point(31, 221), new Point(436, 221), new Point(31, 275), new Point(436, 275)];
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_1:OtherEquipItem = null;
            var _loc_2:int = 0;
            super.createDisposedChildrenImpl();
            this._growSp = UIFactory.getUICompoment(GSprite, 0, 0, this);
            this._talentSp = UIFactory.getUICompoment(GSprite, 0, 0, this);
            this._leftBg = UIFactory.gBitmap(ImagesConst.PetInfoGroupSpBg, 19, 195, this);
            this._rBg = UIFactory.gBitmap(ImagesConst.PetInfoGroupSpBg, 423, 195, this);
            this._leftOpenTxt = UIFactory.gTextField("" + Language.getString(71737), 28, 398, 70, 20, this._growSp, GlobalStyle.textFormatHui);
            this._rightOpenTxt = UIFactory.gTextField("" + Language.getString(71738), 433, 398, 100, 20, this._talentSp, GlobalStyle.textFormatHui);
            this._grouthBg1 = UIFactory.gBitmap(ImagesConst.PetInfoGrouthItemBg, 0, 0);
            this._grouthBg2 = UIFactory.gBitmap(ImagesConst.PetInfoGrouthItemBg, 0, 0);
            this._petGrouthItem = UIFactory.getUICompoment(BaseItem);
            this._petGrouthItem.setItemStyle(ItemStyleConst.Small, ImagesConst.FashionEquipBg, 9, 9);
            this._petGrouthItem.isSHowQuality = false;
            this._petGrouthItem.isShowColorBg = false;
            UIFactory.setObjAttri(this._petGrouthItem, 28, 347, -1, -1, this._growSp);
            this._petGrouthItem.itemData = new ItemData(grouthItemCode);
            this._petTalentItem = UIFactory.getUICompoment(BaseItem);
            this._petTalentItem.setItemStyle(ItemStyleConst.Small, ImagesConst.FashionEquipBg, 9, 9);
            this._petTalentItem.isSHowQuality = false;
            this._petTalentItem.isShowColorBg = false;
            UIFactory.setObjAttri(this._petTalentItem, 433, 347, -1, -1, this._talentSp);
            this._petTalentItem.itemData = new ItemData(tatlentItemCode);
            this._itemArr = [];
            while (_loc_2 < 4)
            {
                
                _loc_1 = UICompomentPool.getUICompoment(OtherEquipItem);
                _loc_1.setItemStyle(ItemStyleConst.Small, ImagesConst.EquipItemBg, 7, 7);
                _loc_1.isAutoUpdateEquip(true, EGroup._EGroupProp, EProp._EPropPet2Equip, _loc_2, EPlayerItemPosType._EPlayerItemPosTypePet);
                _loc_1.isDragAble = false;
                _loc_1.isDragAble = false;
                _loc_1.isShowLock = true;
                _loc_1.pos = _loc_2;
                _loc_1.x = this._posArr[_loc_2].x;
                _loc_1.y = this._posArr[_loc_2].y;
                _loc_1.doubleClickEnabled = true;
                _loc_1.configEventListener(MouseEvent.CLICK, this.openSmallWin);
                _loc_1.configEventListener(MouseEvent.DOUBLE_CLICK, this.putOffEquip);
                this._itemArr.push(_loc_1);
                this.addChild(_loc_1);
                _loc_2++;
            }
            this._mountSharpItem = UICompomentPool.getUICompoment(OtherEquipItem);
            this._mountSharpItem.isSHowQuality = false;
            this._mountSharpItem.isShowColorBg = false;
            this._mountSharpItem.doubleClickEnabled = true;
            this._mountSharpItem.setItemStyle(ItemStyleConst.Small, ImagesConst.PrescriptionEquipBg, 10, 13);
            this._mountSharpItem.x = 33;
            this._mountSharpItem.y = 195 - 83;
            this._mountSharpItem.pos = 4;
            this._mountSharpItem.configEventListener(MouseEvent.CLICK, this.openWardrobeHandler);
            this.addChild(this._mountSharpItem);
            this._itemArr.push(this._mountSharpItem);
            this._wardrobeEnterBtn = UIFactory.gLoadingButton(ResFileConst.WardrobeEnterBtn, 33 + 9, 112 + 58, 46, 23, this);
            this._wardrobeEnterBtn.configEventListener(MouseEvent.CLICK, this.openWardrobeHandler);
            this._petGrouthUseBtn = UIFactory.gLoadedButton(ImagesConst.sub4_upSkin, 66, 346, 18, 18);
            this._petGrouthUseBtn.configEventListener(MouseEvent.CLICK, this.useItemHandler);
            this._growSp.addChild(this._petGrouthUseBtn);
            this._petTalentUseBtn = UIFactory.gLoadedButton(ImagesConst.sub4_upSkin, 475, 346, 18, 18);
            this._petTalentUseBtn.configEventListener(MouseEvent.CLICK, this.useItemHandler);
            this._talentSp.addChild(this._petTalentUseBtn);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            var _loc_2:int = 0;
            var _loc_3:OtherEquipItem = null;
            super.disposeImpl(param1);
            this._leftBg = null;
            this._rBg = null;
            this._leftOpenTxt = null;
            this._rightOpenTxt = null;
            this._grouthBg1 = null;
            this._grouthBg2 = null;
            this._petGrouthItem = null;
            this._petTalentItem = null;
            if (this._wardrobeEnterBtn)
            {
                this._wardrobeEnterBtn.dispose();
                this._wardrobeEnterBtn = null;
            }
            if (this._isHideFasion)
            {
                this._isHideFasion.dispose(param1);
                this._isHideFasion = null;
            }
            this._mountSharpItem = null;
            this._petGrouthUseBtn.dispose(param1);
            this._petGrouthUseBtn = null;
            this._petTalentUseBtn.dispose(param1);
            this._petTalentUseBtn = null;
            if (this._itemArr)
            {
                _loc_2 = 0;
                while (_loc_2 < 4)
                {
                    
                    _loc_3 = this._itemArr[_loc_2];
                    _loc_3.dispose(param1);
                    _loc_2++;
                }
            }
            this._itemArr = null;
            this._growSp.dispose(param1);
            this._growSp = null;
            this._talentSp.dispose(param1);
            this._talentSp = null;
            if (EquipBaseWin.isViewShow)
            {
                EquipBaseWin.instance.hide();
            }
            return;
        }// end function

        private function changeSelected(event:Event) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetChangeSharp, null));
            return;
        }// end function

        protected function addHideFasionBtn() : void
        {
            if (this._isHideFasion == null)
            {
                this._isHideFasion = UIFactory.checkBox("" + Language.getString(71739), 0, 0, 130, 28, this);
                this._isHideFasion.configEventListener(Event.CHANGE, this.changeSelected);
            }
            this._isHideFasion.x = this._mountSharpItem.x;
            this._isHideFasion.y = this._mountSharpItem.y + this._mountSharpItem.height + 2;
            this._isHideFasion.visible = false;
            return;
        }// end function

        public function shapeCardStatUpdate() : void
        {
            if (this._isHideFasion)
            {
                this._isHideFasion.selected = Cache.instance.newPet.pet.shapeCardStatus == 1;
            }
            return;
        }// end function

        protected function removeHideFasionBtn() : void
        {
            if (this._isHideFasion)
            {
                this._isHideFasion.dispose();
                this._isHideFasion = null;
            }
            return;
        }// end function

        private function openSmallWin(event:MouseEvent) : void
        {
            var _loc_2:* = event.currentTarget as OtherEquipItem;
            var _loc_3:* = _loc_2.localToGlobal(new Point(0, 0));
            if (_loc_2 && this._itemArr.indexOf(_loc_2) % 2 == 1)
            {
                _loc_3.x = _loc_3.x - 412;
            }
            var _loc_4:* = this.getSmallWinTitleData();
            EquipBaseWin.instance.setWinData(_loc_4, EPlayerItemPosType._EPlayerItemPosTypePet, EGroup._EGroupProp, EProp._EPropPet2Equip, _loc_2.pos);
            EquipBaseWin.instance.show(_loc_3.x + 92, _loc_3.y - 50);
            return;
        }// end function

        private function putOffEquip(event:MouseEvent) : void
        {
            var _loc_2:* = event.currentTarget as OtherEquipItem;
            if (_loc_2.midLabel)
            {
                return;
            }
            var _loc_3:* = new Object();
            _loc_3.putonitemData = "";
            _loc_3.getoffItemData = Cache.instance.pack.petBag.getEquipByType(_loc_2.itemData.itemInfo.type);
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetEquip, _loc_3));
            return;
        }// end function

        private function getSmallWinTitleData() : Dictionary
        {
            var _loc_1:* = new Dictionary();
            _loc_1[0] = [{name:"equip", label:"" + Language.getString(71744)}];
            _loc_1[1] = [{name:"equip", label:"" + Language.getString(71745)}];
            _loc_1[2] = [{name:"equip", label:"" + Language.getString(71746)}];
            _loc_1[3] = [{name:"equip", label:"" + Language.getString(71747)}];
            _loc_1[4] = [{name:"equip", label:"" + Language.getString(71748)}];
            _loc_1[99] = [{name:"equip", label:"" + Language.getString(71749)}];
            return _loc_1;
        }// end function

        private function getIndexByName(param1:String) : int
        {
            var _loc_2:int = 0;
            switch(param1)
            {
                case "" + Language.getString(71750):
                {
                    _loc_2 = 0;
                    break;
                }
                case "" + Language.getString(71751):
                {
                    _loc_2 = 1;
                    break;
                }
                case "" + Language.getString(71752):
                {
                    _loc_2 = 2;
                    break;
                }
                case "" + Language.getString(71753):
                {
                    _loc_2 = 3;
                    break;
                }
                default:
                {
                    break;
                }
            }
            return _loc_2;
        }// end function

        private function openWardrobeHandler(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.WardrobeOpenWardrobe, EAdvanceComponentType._EAdvanceComponentTypePet));
            return;
        }// end function

        private function useItemHandler(event:MouseEvent) : void
        {
            var _loc_2:ItemData = null;
            var _loc_3:Array = null;
            if (event.currentTarget == this._petGrouthUseBtn)
            {
                if (this._petGrouthItem.amount > 0)
                {
                    _loc_3 = Cache.instance.pack.backPackCache.getItemsByGroupCategoryAndType(EGroup._EGroupStuff, EStuff._EStuffAdvance, EAdvanceType._EAdvanceTypePet2Growth);
                    _loc_2 = _loc_3[0] as ItemData;
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.MountUseGrouthItem, _loc_2));
            }
            else if (event.currentTarget == this._petTalentUseBtn)
            {
                if (this._petTalentItem.amount > 0)
                {
                    _loc_3 = Cache.instance.pack.backPackCache.getItemsByGroupCategoryAndType(EGroup._EGroupStuff, EStuff._EStuffAdvance, EAdvanceType._EAdvanceTypePet2Talent);
                    _loc_2 = _loc_3[0] as ItemData;
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.MountUseGrouthItem, _loc_2));
            }
            return;
        }// end function

        public function updateEquip() : void
        {
            var _loc_3:ItemData = null;
            var _loc_4:OtherEquipItem = null;
            var _loc_1:* = Cache.instance.pack.petBag.allItems;
            var _loc_2:* = _loc_1.length;
            var _loc_5:int = 0;
            while (_loc_5 < 4)
            {
                
                _loc_4 = this._itemArr[_loc_5];
                _loc_4.itemData = new ItemData(getItemCodeByIndex(_loc_5));
                _loc_4.midLabel = getItemNameByIndex(_loc_5);
                _loc_4.bitmapEnable = false;
                _loc_4.setColorBg(0);
                _loc_4.clearStrengInfo();
                _loc_5++;
            }
            this._mountSharpItem.itemData = null;
            this._mountSharpItem.midLabel = "" + Language.getString(71754);
            _loc_5 = 0;
            while (_loc_5 < _loc_2)
            {
                
                _loc_3 = _loc_1[_loc_5];
                if (_loc_3)
                {
                    _loc_4 = this._itemArr[_loc_3.itemInfo.type];
                    _loc_4.itemData = _loc_3;
                    _loc_4.midLabel = "";
                    _loc_4.bitmapEnable = true;
                    _loc_4.updateStrengLevel(_loc_3.itemInfo.itemLevel);
                }
                _loc_5++;
            }
            if (this._mountSharpItem.itemData)
            {
                this.addHideFasionBtn();
                this.shapeCardStatUpdate();
            }
            else
            {
                this.removeHideFasionBtn();
            }
            return;
        }// end function

        public function updateMountInfo(param1:SPublicPet2) : void
        {
            this._petData = param1;
            if (this._petData.code >= 4)
            {
                this.setFilter(this._petGrouthItem, true);
                this._petGrouthItem.filters = null;
                if (this._petData.code >= 5)
                {
                    this.setFilter(this._petTalentItem, true);
                    this._petTalentItem.enabled = true;
                }
                else
                {
                    this.setFilter(this._petTalentItem, false);
                    this._petTalentItem.enabled = false;
                }
            }
            else
            {
                this.setFilter(this._petGrouthItem, false);
                this.setFilter(this._petTalentItem, false);
            }
            this.updatePetItem();
            this.updateTip45();
            return;
        }// end function

        private function setFilter(param1:BaseItem, param2:Boolean) : void
        {
            param1.filters = param2 ? (null) : ([FilterConst.colorFilter2]);
            return;
        }// end function

        public function updatePetItem() : void
        {
            this._petGrouthItem.amount = Cache.instance.pack.backPackCache.getItemCountByCategoryAndType(EGroup._EGroupStuff, EStuff._EStuffAdvance, EAdvanceType._EAdvanceTypePet2Growth);
            this._petTalentItem.amount = Cache.instance.pack.backPackCache.getItemCountByCategoryAndType(EGroup._EGroupStuff, EStuff._EStuffAdvance, EAdvanceType._EAdvanceTypePet2Talent);
            if (this._petGrouthItem.amount > 0 && this._petData && this._petData.code >= 4)
            {
                this._petGrouthUseBtn.visible = true;
                EffectManager.glowFilterReg(this._petGrouthUseBtn);
            }
            else
            {
                this._petGrouthUseBtn.visible = false;
                EffectManager.glowFilterUnReg(this._petGrouthUseBtn);
            }
            if (this._petTalentItem.amount > 0 && Cache.instance.newPet.pet.code >= 5)
            {
                this._petTalentUseBtn.visible = true;
                EffectManager.glowFilterReg(this._petTalentUseBtn);
            }
            else
            {
                this._petTalentUseBtn.visible = false;
                EffectManager.glowFilterUnReg(this._petTalentUseBtn);
            }
            return;
        }// end function

        private function updateTip45() : void
        {
            if (Cache.instance.newPet.pet && Cache.instance.newPet.pet.code >= 4)
            {
                this._leftOpenTxt.visible = false;
            }
            else
            {
                this._leftOpenTxt.visible = true;
            }
            if (Cache.instance.newPet.pet && Cache.instance.newPet.pet.code >= 5)
            {
                this._rightOpenTxt.visible = false;
            }
            else
            {
                this._rightOpenTxt.visible = true;
            }
            return;
        }// end function

        public static function getItemNameByIndex(param1:int) : String
        {
            var _loc_2:String = null;
            switch(param1)
            {
                case 0:
                {
                    _loc_2 = "" + Language.getString(71740);
                    break;
                }
                case 1:
                {
                    _loc_2 = "" + Language.getString(71741);
                    break;
                }
                case 2:
                {
                    _loc_2 = "" + Language.getString(71742);
                    break;
                }
                case 3:
                {
                    _loc_2 = "" + Language.getString(71743);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return _loc_2;
        }// end function

        public static function getItemCodeByIndex(param1:int) : int
        {
            var _loc_2:int = 0;
            switch(param1)
            {
                case 0:
                {
                    _loc_2 = 320000003;
                    break;
                }
                case 1:
                {
                    _loc_2 = 320010003;
                    break;
                }
                case 2:
                {
                    _loc_2 = 320020003;
                    break;
                }
                case 3:
                {
                    _loc_2 = 320030003;
                    break;
                }
                default:
                {
                    break;
                }
            }
            return _loc_2;
        }// end function

    }
}
